


import React, { useEffect, useState } from "react"

import { parkPress, parkPressApi } from "../api/api"
import Page from "./Page"


export default function ParkNews() {

   const [list, setlist] = useState([])

   // 页数
   const [pageNum, setPageNum] = useState(1)
   // 一页显示数量
   const [pageSize, setPageSize] = useState(5)
   // 总页数
   const [pages, setPages] = useState(1)

   const parknew = async (params: any) => {
      const res = await parkPressApi(params)
      setlist(res.data.rows)
      setPages(Math.ceil(res.data.total / pageSize))
   }


   async function onChangePage(val: any) {
      parknew({
         pageNum: val,
         pageSize: 5
      })
      setPageNum(val)
   }

   useEffect(() => {
      parknew({ pageNum, pageSize })
   }, [])


   return (
      <div>
         <div>
            {
               list.map((item: any, index: any) => {
                  return (
                     <div style={{ border: '1px solid red', padding: '5px 5px',margin: '5px 0' }}>
                        <h3 style={{ padding: '10px 0' }}>{item.title}</h3>
                        <div style={{ padding: '5px 0' ,fontSize : '14px'}}>{item.publishDate}</div>

                        <div style={{ padding: '5px 0' ,display : 'flex' ,fontSize : '14px'}} >
                           <p style={{marginRight: '40px'}}>
                              点赞{item.likeNum}
                           </p>
                           <p>
                              评论数{item.commentNum}
                           </p>
                        </div>
                        {/* <div>评论数{item.commentNum}</div> */}
                     </div>

                  )
               })
            }
         </div>
         <Page onChangePage={onChangePage} pagebtnall={pages} pagebtnnum={5} pagecur={pageNum}></Page>
      </div>
   )
}